package second.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Solution17 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, (o1, o2) -> {
            if (o1[0] != o2[0])
                return Integer.compare(o1[0], o2[0]);
            else return Integer.compare(o1[1], o2[1]);
        });
        int res = 1;
        int cover = points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] > cover) {
                res++;
                cover = points[i][1];
            }else cover = Math.min(cover, points[i][1]);
        }
        return res;
    }
}

